from util.common import *

if __name__ == '__main__':

    list = []
    with open('/source/b.txt', 'r', encoding='utf-8') as file:
        createTimes = iter(generate_workdays('2024-01-01', '2024-12-31', 6))
        for line in file:
            fullname = line.strip()
            createTime = next(createTimes)

            id = "TASKZX" + random_string(14)
            seep = {
                "taskId": id,
                "toolTaskId": id,
                "taskName": fullname,
                "taskSource": '30',
                "taskType": '0',
                "status": 12,
                "relateOrder": "",
                "reviewTool": "ASSE1606187013608720",
                "toolOsId": "SCANER243005000",
                "columType": 0,
                "reviewEngine": None,
                "reviewTmpl": None,
                "isJ2ee": 0,
                "jdkVersion": "4",
                "uploadSource": 0,
                "sourceFilePath": "/opt/satp/smp_template/policy/zx/审批附件.zip",
                "taskDesc": "",
                "startTime": f"to_date('{createTime}', 'yyyy-mm-dd hh24:mi:ss')",
                "creator": "PORT6452766823027939",
                "createTime": f"to_date('{createTime}', 'yyyy-mm-dd hh24:mi:ss')",
                "updator": "PORT6452766823027939",
                "updateTime": f"to_date('{createTime}', 'yyyy-mm-dd hh24:mi:ss')",
                "confStr": '{"source":"local","url":"","branch":"","projectType":"0","os":"1","language":"0","codeType":"0","jdkVersion":"4","isJ2ee":"0","reviewEngine":"0","templateId":"467"}',
                "pkReport": "77777"
            }
            message1 = render_template("""
               INSERT INTO TF_SMP_CODE_REVIEW_TASK
                (
                  TASK_ID,
                  TOOL_TASK_ID,
                  TASK_NAME,
                  TASK_SOURCE,
                  TASK_TYPE,
                  STATUS,
                  RELATE_ORDER,
                  TOOL_ASSET_ID,
                  TOOL_OS_ID,
                  COLUM_TYPE,
                  REVIEW_ENGINE,
                  REVIEW_TMPL,
                  IS_J2EE,
                  JDK_VERSION,
                  UPLOAD_SOURCE,
                  SOURCE_FILE_PATH,
                  TASK_DESC,
                  START_TIME,
                  CREATOR,
                  CREATE_TIME,
                  UPDATOR,
                  UPDATE_TIME,
                  CONF_STR,
                  PK_REPORT
                )
                VALUES(
                    $taskId,
                    $toolTaskId,
                    $taskName,
                    $taskSource,
                    $taskType,
                    $status,
                    $relateOrder,
                    $reviewTool,
                    $toolOsId,
                    $columType,
                    $reviewEngine,
                    $reviewTmpl,
                    $isJ2ee,
                    $jdkVersion,
                    $uploadSource,
                    $sourceFilePath,
                    $taskDesc,
                    $startTime,
                    $creator,
                    $createTime,
                    $updator,
                    $updateTime,
                    $confStr,
                    $pkReport
                );
            """, seep)

            list.append(message1)

            report = {
                "confId": id,
                "assetId": "ASSE6389925744609193",
                "updateTime": f"to_date('{createTime}', 'yyyy-mm-dd hh24:mi:ss')",
            }

            message2 = render_template(
                """
                        INSERT INTO TF_SMP_REVIEW_TOOL_CONF (CONF_ID, ASSET_ID, STATUS, UPDATE_TIME)
                        VALUES ($confId, $assetId, 0, $updateTime);
                    """,
                report)
            list.append(message2)

            log = {
                "restId": id,
                "taskId": id,
                "costTime": None,
                "resultCode": 0,
                "infoNum": 0,
                "lowNum": 1,
                "midNum": 0,
                "critNum": 0,
                "addInfo": None,
                "createTime": f"to_date('{createTime}', 'yyyy-mm-dd hh24:mi:ss')",
            }

            message3 = render_template(
                """
                            INSERT INTO tf_smp_review_result_count(REST_ID,
                                           TASK_ID,
                                           COST_TIME,
                                           RESULT_CODE,
                                           INFO_NUM,
                                           LOW_NUM,
                                           MID_NUM,
                                           CRIT_NUM,
                                           ADD_INFO,
                                           CREATE_TIME)
                        VALUES ($restId,
                                $taskId,
                                $costTime,
                                $resultCode,
                                $infoNum,
                                $lowNum,
                                $midNum,
                                $critNum,
                                $addInfo,
                                $createTime);
                                """, log)
            list.append(message3)

            log4 = {
                "detId": id,
                "taskId": id,
                "bugName": 'WebRoot/javascript/eval.js',
                "bugType": None,
                "bugLevel": 1,
                "bugDsc": "程序创建或分配数据库资源后，不进行合理释放，将会降低系统性能。",
                "bugEffect": None,
                "bugPosition": "AAAAA",
                "solution": "程序不应依赖于虚拟机的finalize()方法自动的回收数据库资源，而应手动在finally代码块中进行数据库资源释放操作。",
                "createTime": f"to_date('{createTime}', 'yyyy-mm-dd hh24:mi:ss')",
            }

            message4 = render_template(
                """
                            INSERT INTO TF_SMP_REVIEW_BUG_DETAIL(DET_ID,
                                         TASK_ID,
                                         BUG_NAME,
                                         BUG_TYPE,
                                         BUG_LEVEL,
                                         BUG_DSC,
                                         BUG_EFFECT,
                                         BUG_POSITION,
                                         SOLUTION,
                                         CREATE_TIME)
                            VALUES ($detId,
                                    $taskId,
                                    $bugName,
                                    $bugType,
                                    $bugLevel,
                                    $bugDsc,
                                    $bugEffect,
                                    $bugPosition,
                                    $solution,
                                    $createTime);
                                """, log4)
            list.append(message4)

            file = {
                "fileUploadId": "FILEZX" + random_string(14),
                "fileName": fullname,
                "filePath": "/opt/satp/smp_template/policy/zx/" + fullname,
                "oid": id,
                "fileDesc": None,
                "fileType": None,
            }

            message4 = render_template(
                """
                            INSERT INTO TF_H_FILEUPLOAD (ID, FILE_NAME, FILE_PATH, OID, FILE_DESC, FILE_TYPE)
                            VALUES ($fileUploadId, $fileName, $filePath, $oid, $fileDesc,$fileType);
            """, file)
            list.append(message4)

    write_file('target/SATP_代码审计.sql', list)
       
